'use strict';

const dayjs = require('dayjs');

module.exports = app =>{
    const { STRING, INTEGER, DATE } = app.Sequelize;

    const article = app.model.define('article',{
        id: {
          type: INTEGER, primaryKey: true, autoIncrement: true,
        },
        title:STRING(60),
        authorId:INTEGER(6),
        content:STRING(1000),
        tags:STRING(60),
        view_count:INTEGER(20),
        like_count:INTEGER(20),
        collect_count:INTEGER(20),
        main_img:STRING(255),
        topic:STRING(255),
        status:INTEGER(4),
        create_time:{
            type:DATE,
            get(){
                const time = this.getDataValue('create_time');
                return time ? dayjs(time).format('YYYY-MM-DD HH:mm:ss') : null
            }
        },
        audit_time:{
            type:DATE,
            get(){
                const time = this.getDataValue('audit_time');
                return time ? dayjs(time).format('YYYY-MM-DD HH:mm:ss') : null
            }
        },
        delete_time:{
            type:DATE,
            get(){
                const time = this.getDataValue('delete_time');
                return time ? dayjs(time).format('YYYY-MM-DD HH:mm:ss') : null
            }
        },
        draft_time:{
            type:DATE,
            get(){
                const time = this.getDataValue('delete_time');
                return time ? dayjs(time).format('YYYY-MM-DD HH:mm:ss') : null
            }
        },
        draft_update_time:{
            type:DATE,
            get(){
                const time = this.getDataValue('delete_time');
                return time ? dayjs(time).format('YYYY-MM-DD HH:mm:ss') : null
            }
        },
    },{
        freezeTableName: false,
        tableName: 'article',
        underscored: false,
        paranoid: true,
        timestamps: true,
        createdAt: false,
        updatedAt: false,
        deletedAt: 'delete_time',
    })
    return article;
}